package com.example.cyk.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.cyk.myapplication.utils.PopupUtils;

/**
 * Created by cyk on 2014-10-13.
 */
public class SecondActivity extends Activity {

    WebView myView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_activity);
        Log.i("log", "onCreate");

        myView = (WebView)findViewById(R.id.webView);
        myView.loadUrl("http://m.blog.naver.com/1000glory");

        //commit test
        myView.setWebViewClient(new MyView());
    }

    class MyView extends WebViewClient{
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            view.loadUrl(url);
            return true;
        }
    }
    public void onPrevActivity(View v){
        Intent intent  = new Intent(this, MyActivity.class);
        startActivity(intent);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        Log.i("log", "onCreateOptionsMenu");
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && myView.canGoBack()) {
            myView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        PopupUtils popup = new PopupUtils(this);
        if (id == R.id.action_onPopup) {
            popup.onPopup("한글", "한글");
            return true;
        }
        if (id == R.id.action_onExitPopup) {
            popup.onExitPopup("Are you sure you want to exit?");
            return true;
        }
        if (id == R.id.action_onListPopup) {
            final CharSequence[] items = {"Red", "Green", "Blue"};
            popup.onListPopup("Pick a color", items);
            return true;
        }
        if (id == R.id.action_onCheckPopup) {
            final CharSequence[] items = {"Red", "Green", "Blue"};
            final boolean[] itemsChecked = {false, true, false};
            popup.onCheckPopup("Pick a color", items, itemsChecked);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
